#ifndef __UI_H__
#define __UI_H__
#define WIDTH 999
#define HEIGHT 666
#define MAX_ELEMENT_COUNT 64
#include <easyx.h>
#include "../src/UI/element/Element.h"
#include "procedure.h"
#include "../src/ui/element/Map.h"
#include <font.h>
#include <map>

//UI_ID
const int INIT_UI = 0;
const int ROOM_UI = 1;
const int SEARCH_ROOM_UI = 2;
const int GAME_UI = 3;
extern int Tick;
extern int nowElementCount;
extern int nowInteractiveElementCount;
extern int nowInputElementCount;
extern int nowDoubleClickCount;
extern FontStyle DefaultFont;
extern Element *Elements[MAX_ELEMENT_COUNT];
extern Element *InteractiveElements[MAX_ELEMENT_COUNT];
extern Element *InputElements[MAX_ELEMENT_COUNT];
extern Element *DoubleClickElements[MAX_ELEMENT_COUNT];
//key
bool IsLeftKeyPressing();
bool IsRightKeyPressing();
void SetListenKey(char key);
long long GetKeyPressTime(char key);
//ui
int GetNowUI();
void SetNowUI(int now);
void CrashCurrentUI();
void RedrawCurrentUI();
void InitUI();
void ShowInitUI();
void ShowRoomUI(bool isHost, bool *playerList = nullptr, int myId = 0);
void ShowSearchRoomUI();
void ShowGameUI(char id,Map *map,Player *players);
void AddRoomToListUI(char* info);
//element
void RegisterElement(Element *e);
void RegisterInput(Element *input);
void RegisterDoubleClick(Element *e);
char* GetInputValue(char *id);
//basic handler
void handleLocalKey();
void handleLeftUp(int x,int y);
void handleChar(char c);
void handleMouseMove(int x,int y);
void handleDoubleClick(int x,int y);
//default handler
int onCreateRoomButtonClick(void *args);
int onFindRoomButtonClick(void *args);
int onSettingsButtonClick(void *args);
int backHome(void *args);
int onRoomButtonDoubleClick(void *arg);
int backHomeFromHost(void *args);
int backHomeFromFindRoom(void *args);
int onJoinRoomButtonClick(void *args);
int backFindRoomFromRemoteRoom(void  *args);
int onGameStartButtonClick(void *args);
int onQuitGameButtonDoubleClick(void *args);
//game
void LoadGameImage();
void ReDrawMap(Map &myMap, Player *players, std::map<int,Projectile>  *playerProjectiles);
void RefreshPlayerInfoUI(Player *pls);
#endif